﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Admin_QuanLyNhomHangHoa_SuaNhomHangHoa : System.Web.UI.Page
{
    private string strMa = string.Empty;
    private DataAccess da = new DataAccess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminID"] == null)
        {
            Response.Write("<script language='javascript'>alert('Bạn phải đăng nhập / You must login');location.href='/../Admin/Login.aspx';</script>");
        }
        if (Request.QueryString["maNh"] != null && Request.QueryString["maNh"].ToString() != "")
        {
            strMa = Request.QueryString["maNh"].ToString();
        }
        if (!IsPostBack)
        {
            this.GetNhomHanginfo(strMa);
        }
    }
    protected void GetNhomHanginfo(string ma)
    {
        SqlDataReader drd;
        SqlCommand comm = new SqlCommand("getNhomHangHoabyMa", da.SqlConn());
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.AddWithValue("@Ma", ma);
        comm.Connection.Open();
        drd = comm.ExecuteReader();
        if (drd.Read())
        {
            this.txtMa.Text = drd["MaNhomHang"].ToString();
            this.txtTen.Text = drd["TenNhomHang"].ToString();
        }
        drd.Close();
        drd.Dispose();
        comm.Connection.Close();
        comm.Connection.Dispose();

    }
    protected void NhomHangHoa_Edit_Click(object sender, EventArgs e)
    {

        EditNhomHangHoa();

    }
    protected void EditNhomHangHoa()
    {
        string strTen = this.txtTen.Text;

        SqlCommand comm = new SqlCommand("updateNhomHangHoa", da.SqlConn());
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.AddWithValue("@Ma", strMa);
        comm.Parameters.AddWithValue("@Ten", strTen);

        comm.Connection.Open();
        comm.ExecuteNonQuery();




        comm.Connection.Close();
        comm.Connection.Dispose();
        Response.Redirect("DanhSachNhomHangHoa.aspx");

    }
}
